package cn.lijunkui.jedis;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import javax.annotation.Resource;

@ExtendWith(SpringExtension.class)
@SpringBootTest
public class JedisUser {
    Logger log = LoggerFactory.getLogger(JedisUser.class);
    @Resource
    private JedisPool jedisPool;

    @Test
    public void set() {
        try (Jedis jedis =new Jedis("localhost",6379 )) {
            jedis.auth("123456");
            jedis.set("a", "1");
            log.info("set 返回值是：{}" );
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Test
    public void get(){
        try (Jedis jedis = new Jedis("localhost", 6379)) {
            String returnVlaue = jedis.get("a");
            log.info("key 为 a的值是：{}", returnVlaue);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Test
    public void del(){
        try (Jedis jedis = new Jedis("localhost", 6379)) {
            long count = jedis.del("a");
            log.info("删除 key 为 a 的值");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
